/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package bgtp;

import java.util.*;
import java.lang.*;

public class Filter
{
    private ASTNode	root;
    private String	expression;
    private ASTBuilder	maker;

    public Filter()
    {
	maker	   = new ASTBuilder(); 
	root	   = null;
    }

    public Filter(String exp)
    {
	this();
	make(exp); //мобыть стоит бросить ексепшн в случае чего
    }

    public boolean make(String exp) 
    {
	if(root != null)
	    {
		root.destroy();
		root = null;
	    }
	
	expression = exp;
	root	   = maker.build(exp);

	if(root == null)
	    {
		return false;
	    }

	return true;
    }

    public boolean check(TreeMap<String, String> stuff_)
    {
	return root.call(stuff_);
    }
}
